import {defineStore} from 'pinia';
import {Http, Cache, Helper, Msg} from 'core';
import userStore from '@/stores/framework/user';
const UserStore = userStore();
const store = {
    id: "company",
    state() {
        return {
            companyConfig: {},

            companyInfo: {}
        }
    },

    getters: {

    },

    actions: {

        /**
         * 查询公司信息
         * @returns {Promise<null|*>}
         */
        async getInfo() {
            let companyId = UserStore.getUser().companyId;
            Msg.loading("加载中...")
            this.companyInfo = {};
            let {code, data} = await Http.get("/company/getCompany/" + companyId);
            Msg.loading(false);
            if(code == 200) {
                if(Helper.empty(data)) {
                    Msg.error("获取配置信息出错");
                    return;
                }
                this.companyInfo = data;
                return data;
            }
            return null;
        },

        /**
         * 读取公司配置
         * @returns {Promise<*>}
         */
        async getConfig() {
            let companyId = UserStore.getUser().companyId;
            Msg.loading("加载中...")
            this.companyConfig = {};
            let {code, data} = await Http.get("/company/getCompanyConfig/" + companyId);
            Msg.loading(false);
            if(code == 200) {
                if(Helper.empty(data)) {
                    Msg.error("获取配置信息出错");
                    return;
                }
                this.companyConfig = data;
                return data;
            }
            return null;
        }
    }
}

export default defineStore(store)
